
/**
 * @Project : Clion_ProgrammingExercises
 * @File : 1
 * @Author : WangRuoyu 
 * @Date : 2023/5/18 15:57
 */

#include "iostream"
#include "cstring"
#include "algorithm"

using namespace std;

int main() {
    int n;
    cin >> n;
    int max = 0;
    int min = 0;
    int tmp = -1;
    int cnt = 0;

    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        if (x != tmp) {
            if (tmp > 0) {
                max += cnt * tmp;
                min += tmp;
            }
            cnt = 1;
            tmp = x;
        } else {
            cnt++;
        }
    }

    if (tmp > 0) {
        max += cnt * tmp;
        min += tmp;
    }

    cout << max << endl;
    cout << min << endl;

    return 0;
}